package Homework.jdbcWork2;

import jdbc.DButil;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * @author shkstart
 * @creat 2022-05-14:52
 */
public class addStu {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        Connection con = null;
        PreparedStatement ps = null;
        con = DButil.getCon();
        String sql = "insert into s_student(sname,sex,gradeid,fromcity,birthday,enterdate,qq,telephone)values (?,?,?,?,?,?,?,?)";
        try {
            ps = con.prepareStatement(sql);
            System.out.println("姓名：");
            ps.setString(1, sc.next());
            System.out.println("性别：");
            ps.setString(2, sc.next());
            System.out.println("年级编号：");
            ps.setInt(3, sc.nextInt());
            System.out.println("城市：");
            ps.setString(4, sc.next());
            System.out.println("生日：");
            ps.setDate(5, Date.valueOf(sc.next()));
            System.out.println("入学日期：");
            ps.setDate(6, Date.valueOf(sc.next()));
            int i = ps.executeUpdate();
            System.out.println("QQ号");
            ps.setDate(7, Date.valueOf(sc.next()));
            System.out.println("电话号码：");
            ps.setDate(8, Date.valueOf(sc.next()));
            System.out.println(sql);
            System.out.println(i > 0 ? "添加成功" : "添加失败");
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DButil.close(null, ps, con);
        }

    }
}

